package com.salemanagement.controller;

import com.salemanagement.service.OrderService;
import com.salemanagement.service.StoreService;
import com.salemanagement.vo.ProductOrderVo;
import com.salemanagement.vo.QueryParam;
import com.three.core.entity.Product;
import com.three.core.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/saleManagement/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @PostMapping("/findIncome")
    public R findIncome(@RequestBody Map<String, String> queryParam) {
        try {
            List<Map<String, Object>> incomeData = orderService.getIncomeStatistics(
                queryParam.get("date"),
                queryParam.get("storeName")
            );
            return new R<>(200, "查询成功", incomeData);
        } catch (Exception e) {
            return new R<>(500, "获取收入统计失败：" + e.getMessage(), null);
        }
    }
    @GetMapping("/selectAllStore")
    public R selectAllStore() {
        try {
            List<Map<String, Object>> stores = orderService.getAllStores();
            return new R<>(200, "查询成功", stores);
        } catch (Exception e) {
            return new R<>(500, "获取商店列表失败：" + e.getMessage(), null);
        }
    }
    //创建微信支付二维码
    @PostMapping("/createWeChat/{orderNo}")
    public R createWeChat(@PathVariable String orderNo){
        return orderService.createWeChat(orderNo);
    }
    @PostMapping("/queryWeChatPayStatus/{orderNo}")
    public R queryWeChatPayStatus(@PathVariable String orderNo){
        return orderService.queryWeChatPayStatus(orderNo);
    }
    @PostMapping("/PayFinish")
    public R<Product> PayFinish(@RequestParam Integer id){
        return orderService.PayFinish(id);
    }
    @PostMapping("/IntegralPay")
    public R IntegralPay(@RequestBody ProductOrderVo productOrderVo){
        return orderService.IntegralPay(productOrderVo);
    }
    @PostMapping("/createWDPay")
    public R createWDPay(@RequestBody ProductOrderVo productOrderVo){
        return orderService.createWDPay(productOrderVo);
    }
    @PostMapping("/queryWDPayStatus")
    public R queryWDPayStatus(@RequestBody ProductOrderVo productOrderVo){
        return orderService.queryWDPayStatus(productOrderVo);
    }
}
